package com.lmr.boot.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lmr.boot.bean.User;
import com.lmr.boot.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

@Controller
public class TableController {
    @Autowired
    UserService userService;
    @GetMapping("/basic_table")
    public String basic_table(){
        return "table/basic_table";
    }

    @GetMapping("/dynamic_table")
    public String dynamic_table(Model model, @RequestParam(value = "pn",defaultValue = "1") Integer pn){

        List<User> list = userService.list();
        //分页查询数据 ，两个参数 第一个当前页码前端传过来，第二个每页显示几条数据
        Page<User> userPage = new Page<>(pn,2);
        //分页查询结果
        Page<User> page = userService.page(userPage, null);
        model.addAttribute("page",page);
        return "table/dynamic_table";
    }
    @GetMapping("/delete")
    public String DeleteUser(Long id,@RequestParam(value = "page",defaultValue = "1") Integer page){
        userService.removeById(id);
        return "redirect:/dynamic_ table?pn="+page;
    }

    @GetMapping("/responsive_table")
    public String responsive_table(){
        return "table/responsive_table";
    }
    @GetMapping("/editable_table")
    public String editable_table(){
        return "table/editable_table";
    }



}
